package cn.xz.kjg.adapter

import android.widget.TextView
import cn.xz.kjg.R
import cn.xz.kjg.bean.DeviceList
import cn.xz.kjg.bean.Flash
import cn.xz.kjg.util.LocalHttp
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 *本地列表适配器*/
class LocalListAdapter(mDevice: DeviceList): BaseQuickAdapter<Flash, BaseViewHolder>(R.layout.item_local_list) {

    private var selectPosition = -1

    private var mDevice = mDevice

    override fun convert(holder: BaseViewHolder, item: Flash) {
        val mText = holder.getView<TextView>(R.id.channel_item_tv)

        if (item.title.length > 10) {
            mText.textSize = 14f
        } else {
            mText.textSize = 16f
        }
        mText.text = item.title
        mText.isSelected = holder.adapterPosition == selectPosition

        mText.setOnClickListener {
            selectPosition = holder.adapterPosition
            LocalHttp.playLocal(mDevice.ip,holder.adapterPosition)
            notifyDataSetChanged()
        }

    }
}